<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.keyword" placeholder="关键字"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getWebLogs">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="webLogs" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column type="selection" width="80">
			</el-table-column>
			<el-table-column type="index" width="80">
			</el-table-column>
			<el-table-column prop="username" label="用户名" width="100" sortable>
			</el-table-column>
			<el-table-column prop="description" label="描述" width="200" sortable>
			</el-table-column>
			<el-table-column prop="method" label="方法" width="300" sortable>
			</el-table-column>
			<el-table-column prop="ip" label="终端ip" width="200" sortable>
			</el-table-column>
			<el-table-column :formatter="formatDate" prop="createDate" label="创建时间" sortable>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next"
						   @current-change="handleCurrentChange"
						   :page-size="pageSize"
						   :current-page="currentPage"
						   :total="total"
						   style="float:right;">
			</el-pagination>
		</el-col>

		<!--修改或者新增界面-->
	</section>
</template>

<script>


	export default {
		data() {
			return {
				filters: {
					keyword: ''
				},
                webLogs: [],
				total: 0,
				currentPage: 1,
                pageSize: 10,
				listLoading: false,
			}
		},
		methods: {

			handleCurrentChange(val) {
				this.currentPage = val;
				this.getWebLogs();
			},
			//获取部门列表
			getWebLogs() {
				let para = {
                    currentPage: this.currentPage,
					pageSize: this.pageSize,
					keyword: this.filters.keyword
				};
				this.listLoading = true;

                this.$http.post("/weblog/page",para).then(result => {
                    this.listLoading = false;
                    this.webLogs = result.data.rows;
					this.total = result.data.totals;
				})

			},
			//删除
			handleDel: function (index, row) {
				this.$confirm('确认删除该记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();

					/*removeWebLog(para).then((res) => {
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
						this.getWebLogs();
					});*/
					//发送请求
					this.$http.delete("/weblog/delete/"+row.id)
						.then(result => {
                            this.listLoading = false;
                            result = result.data;
                            if(result.success){
                                this.$message({
                                    message: result.message,
                                    type: 'success'
                                });
                                //定位到第一页
								this.currentPage = 1;
                                this.getWebLogs();
							}else {
                                this.listLoading = false;
                                this.$message({
                                    message: result.message,
                                    type: 'error'
                                });
							}
						})
						.catch(result => {
                            this.listLoading = false;
                            this.$message({
                                message: "系统错误，正在殴打程序员",
                                type: 'error'
                            });
						})
				}).catch(() => {

				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			//批量删除
			batchRemove: function () {
				var ids = this.sels.map(item => item.id);
				this.$confirm('确认删除选中记录吗？', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					this.$http.patch("/weblog/batch",ids)
                        .then(result => {
                            this.listLoading = false;
                            result = result.data;
                            if(result.success){
                                this.$message({
                                    message: result.message,
                                    type: 'success'
                                });
                                //定位到第一页
                                this.currentPage = 1;
                                this.getWebLogs();
                            }else {
                                this.listLoading = false;
                                this.$message({
                                    message: result.message,
                                    type: 'error'
                                });
                            }
                        })
                        .catch(result => {
                            this.listLoading = false;
                            this.$message({
                                message: "系统错误，正在殴打程序员",
                                type: 'error'
                            });
                        })
				}).catch(() => {

				});
			}
		},
		mounted() {
			this.getWebLogs();
		}
	}

</script>

<style scoped>

</style>